package com.mingqijia.gassafety.webserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mingqijia.gassafety.db.entity.BusinessNoticeTemplate;
import com.mingqijia.gassafety.db.mapper.BusinessNoticeTemplateMapper;
import com.mingqijia.gassafety.webserver.response.BusinessNoticeParamRes;
import com.mingqijia.gassafety.webserver.service.BusinessNoticeTemplateService;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 业务通知规则模板表 服务实现类
 * </p>
 *
 * @Author: duanhongxiang
 * @Date: 2024/1/17 21:43
 */
@Service
@Slf4j

public class BusinessNoticeTemplateServiceImpl extends ServiceImpl<BusinessNoticeTemplateMapper, BusinessNoticeTemplate> implements BusinessNoticeTemplateService {

    @Override
    public List<BusinessNoticeParamRes> getTemplateParamList() {
        List<BusinessNoticeParamRes> resultList = new ArrayList<>();
        LambdaQueryWrapper<BusinessNoticeTemplate> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusinessNoticeTemplate::getIsDeleted, 0);
        queryWrapper.orderByDesc(BusinessNoticeTemplate::getOrdinal).orderByAsc(BusinessNoticeTemplate::getId);
        List<BusinessNoticeTemplate> list = this.list(queryWrapper);
        for (BusinessNoticeTemplate businessNoticeTemplate : list) {
            BusinessNoticeParamRes res = new BusinessNoticeParamRes();
            BeanUtils.copyProperties(businessNoticeTemplate, res);
            res.setParamRemark(businessNoticeTemplate.getRemark());
            resultList.add(res);
        }
        return resultList;
    }

    @Override
    public BusinessNoticeTemplate getTemplateParam(String paramCode) {
        LambdaQueryWrapper<BusinessNoticeTemplate> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BusinessNoticeTemplate::getIsDeleted, 0);
        queryWrapper.eq(BusinessNoticeTemplate::getParamCode, paramCode);
        BusinessNoticeTemplate item = this.getOne(queryWrapper);
        return item;
    }
}
